import axios from 'axios'
import PubSub, { publish }  from 'pubsub-js'
import React, { useState } from 'react'
export default function Header() {
    const [search,setSearch] = useState('')
    const changeSearchHandle=(e)=>{
        setSearch(e.target.value)
    }
    const searchHandle = ()=>{
        //在请求之前传输正在加载
        Pubsub.publish('github',{isInit: false, isSearch: false, data: []})
         const result =axios.get('https://api.github.com/search/users?q='+search)
         PubSub.publish('github',{isInit: false, isSearch: false, data:result.data.itmes })
    }
  return (
    <section className="jumbotron">
      <h3 className="jumbotron-heading">Search Github Users</h3>
      <div>
        <input type="text" value={search} onChange={changeSearchHandle} placeholder="enter the name you search" />
        &nbsp;
        <button onClick={searchHandle}>Search</button>
      </div>
    </section>
  )
}

